<?php
	$chars = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",1,2,3,4,5,6,7,8,9,0);
	$numbChars = 6;
	$code = "";
	$im = imagecreatetruecolor(200, 32);
	$colors = array
		(
			imagecolorallocate($im, 255, 255, 255),
			imagecolorallocate($im, 255, 0, 0),
			imagecolorallocate($im, 0, 255, 0),
			imagecolorallocate($im, 0, 255, 0),
			imagecolorallocate($im, 255, 255, 0),
			imagecolorallocate($im, 0, 255, 255),
			imagecolorallocate($im, 255, 0, 255)
		);
	$black = imagecolorallocate($im, 0, 0, 0);
	imagefilledrectangle($im, 0, 0, 200, 32, $black);
	$font = '../resoursces/fonts/font.ttf';
	for($i = 0; $i < $numbChars; $i++)
	{
		$char = $chars[rand(0, count($chars) - 1)];
		$code .= $char;
		$color = imagecolorallocate($im, rand(10,255), rand(10,255), rand(10,255));
		imagettftext($im, 25, rand(0, 60), ($i * 30) + 20, 25, $color, $font, $char);
	}
	$_SESSION["captchaCode"] = $code;
	header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");
	header("Content-type: image/gif");
	imagegif($im);
	imagedestroy($im);
?>